package com.goldentrail.db;

import java.util.Hashtable;

/**
 * 
 * @author Dey, Saumen
 * @version 1.0, Oct 11, 2011
 *
 */
public class DBInsert {
	
	DBOperation dbo = new DBOperation(true);
	
	public void insUser(String userId, String userName) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("user_id", "'"+userId+"'");
		ht.put("user_name", "'"+userName+"'");
		if (!(dbo.isInDb("user", "user_id", userId))) 
		    dbo.insert(ht, "user");
	}

	public void insWf(String wfId, String wfName, String wfDesc, String userId) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("wf_id", "'"+wfId+"'");
		ht.put("wf_name", "'"+wfName+"'");
		ht.put("wf_desc", "'"+wfDesc+"'");
		ht.put("user_id", "'"+userId+"'");
		if (!(dbo.isInDb("workflow", "wf_id", wfId)))
		   dbo.insert(ht, "workflow");
	}
	
	public void insActor(String actorId, String actoName, String actorURL) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("actor_id", "'"+actorId+"'");
		ht.put("actor_desc", "'"+actoName+"'");
		ht.put("source_url", "'"+actorURL+"'");
		if (!(dbo.isInDb("actor", "actor_id", actorId)))
		   dbo.insert(ht, "actor");	
	}

	public boolean isRunInDb(String runId) {	
		boolean runIsInDb = false; 
		if (dbo.isInDb("run", "run_id", runId))
			runIsInDb = true;
		return runIsInDb;
	}
	
	public void insRun(String runId, String runDetail, String wfId) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("run_id", "'"+runId+"'");
		ht.put("run_detail", "'"+runDetail+"'");
		ht.put("wf_id", "'"+wfId+"'");
		dbo.insert(ht, "run");	
	}
	
	public void insInvocation(String invocId, String actorId, String runId ) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("run_id", "'"+runId+"'");
		ht.put("actor_id", "'"+actorId+"'");
		ht.put("invocation_id", "'"+invocId+"'");
		dbo.insert(ht, "invocation");	
	}

	public void insData(String dataId, String dataName, String dtaURL) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("data_id", "'"+dataId+"'");
		ht.put("data_desc", "'"+dataName+"'");
		ht.put("source_url", "'"+dtaURL+"'");
		if (!(dbo.isInDb("data", "data_id", dataId)))
		   dbo.insert(ht, "data");
	}
	
	public void insUsed(String invocId, String dataId) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("invocation_id", "'"+invocId+"'");
		ht.put("data_id", "'"+dataId+"'");
		dbo.insert(ht, "used");
	}	

	public void insGenBy(String dataId, String invocId) {	
		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("data_id", "'"+dataId+"'");
		ht.put("invocation_id", "'"+invocId+"'");
		dbo.insert(ht, "genBy");
	}
}
